package com.wyix.controller;

import com.wyix.device.Light;
import com.wyix.device.Thermostat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangdx
 * @since 2025/8/19
 */
@RestController
public class HomeController {
    private final Light light;
    private final Thermostat thermostat;

    // 构造函数注入自动配置的Bean
    @Autowired
    public HomeController(Light light, Thermostat thermostat) {
        this.light = light;
        this.thermostat = thermostat;
    }

    @GetMapping("/status")
    public Map<String, String> getHomeStatus() {
        Map<String, String> status = new HashMap<>();
        status.put("light", light.turnOn());
        status.put("temperature", thermostat.setTemperature(23.5));
        status.put("deviceType", light.getType());
        return status;
    }
}
